import time
from threading import Thread
from tkinter import Frame, Label, LEFT, Button, Tk, messagebox

import keyboard
import mouse
import random


class botty_mc_botface:

    def __init__(self):
        self.running = 1

    def terminate(self):
        messagebox.showinfo("提示", "已暂停")
        self.running = 0

    def action(self):
        mouse.press(mouse.LEFT)
        time.sleep(1)
        mouse.release(mouse.LEFT)
        time.sleep(1)
        keyboard.press("R")
        time.sleep(1)
        keyboard.release("R")
        keyboard.press("E")
        time.sleep(1)
        keyboard.release("E")

    #开始
    def botting(self):
        messagebox.showinfo("提示", "开启成功")
        self.running = 1
        start = time.time()
        print(start)
        while self.running:
            time.sleep(1)
            print("running")
            if time.time() > start + 120:
                self.action()
                start = time.time()


class App:
    def __init__(self, master):
        self.bot = botty_mc_botface()
        self.title = "KOTH挂机助手v1.0"
        self.botthread = Thread(target=self.bot.botting)
        title = Frame(master)
        frame = Frame(master)
        frame1 = Frame(master)
        title.pack()
        frame.pack()
        frame1.pack()

        t = Label(title, text="官网:www.arma3.cn", justify=LEFT)
        t.pack(side=LEFT)

        help = Label(frame1, text="快捷键:home-开启|end-暂停", justify=LEFT)
        label = Label(frame1, text="fengzi@arma3.cn|风子", justify=LEFT)
        help.pack()
        label.pack(side=LEFT)

        # 启动按钮
        self.slogan = Button(frame,
                             text="启动",
                             command=self.botthread.start)
        self.slogan.pack(side=LEFT, padx=10, pady=10)

        # 结束按钮
        self.slogan = Button(frame,
                             text="暂停", command=self.bot.terminate)
        self.slogan.pack(side=LEFT, padx=10, pady=10)

        keyboard.add_hotkey('home', self.botthread.start)
        keyboard.add_hotkey('end', self.bot.terminate)


def main():
    root = Tk()
    root.title("KOTH挂机助手v1.0")
    root.geometry("300x150+100+100")
    app = App(root)
    root.mainloop()


if __name__ == '__main__':
    main()
